package cn.feizhu.aimarket.exception;

public class ThrowUtils {

    /**
     * 核心方法，后面是方法重载，根本上是利用这个实现的
     * 根据条件判断功能是否可以实现
     * @param condition 条件
     * @param exception 异常，我们的BusinessException是继承了RuntimeException的
     */
    public static void throwIf(boolean condition, RuntimeException exception) {
        if(condition) {
            throw exception;
        }
    }

    public static void throwIf (boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }
}
